package zyn_hy_login;

public class CheckName
{
	protected static String FirstConn = ConfigurationSettings.AppSettings["connectString"];
	private String stringConn;
	private String stringTable;
	private String tempID2;
	private String tempID3;
	private String tempName;

	public CheckName(String ID2, String ID3, String Name)
	{
		this.tempName = Name;
		this.tempID2 = ID2;
		this.tempID3 = ID3;
		this.First();
	}

	public final void First()
	{
		SqlCommand command = (new SqlConnection(FirstConn)).CreateCommand();
		command.CommandType = CommandType.Text;
		command.CommandText = "select x1 server,x2 Data,x3 uid,x4 pwd,x5 biao from d_a where ID=" + this.tempID3 + "";
		command.Connection.Open();
		SqlDataReader reader = command.ExecuteReader(CommandBehavior.CloseConnection);
		try
		{
			while (reader.Read())
			{
				this.stringConn = "server=" + reader.GetValue(0).toString() + ";User ID=" + reader.GetValue(2).toString() + ";Password=" + reader.GetValue(3).toString() + ";database=" + reader.GetValue(1).toString() + ";Connection Reset=FALSE";
				this.stringTable = reader.GetValue(4).toString();
			}
		}
		finally
		{
			reader.Close();
		}
	}

	public final boolean ValidateName()
	{
		this.First();
		SqlConnection connection = new SqlConnection(this.stringConn);
		SqlCommand command = connection.CreateCommand();
		command.CommandType = CommandType.Text;
		command.CommandText = "select name,id2 from " + this.stringTable.toString() + " where name='" + this.tempName + "' and  ID2=" + this.tempID2.toString() + "";
		command.Connection.Open();
		SqlDataReader reader = command.ExecuteReader();
		try
		{
			if (reader.Read())
			{
				return false;
			}
		}
		finally
		{
			reader.Close();
			connection.Close();
		}
		return true;
	}

	public final String getRecordConn()
	{
		return this.stringConn;
	}

	public final String getTableName()
	{
		return this.stringTable;
	}
}